var rowIndex = "%^%%%%";
var regid = 0;
var flag = true;
var page;
/*
* @Description: 操作事件
* @param :
*/
window.operateEvents= {
'click .revoke' : function(e, value, row, index) {// 打印按钮点击事件
		/*$("#useModal").modal('show');*/
//		var URL = pathUrl("POS?fName=" + row.fName + "&fModel=" + row.fModel + "&fBatchNo=" +row.fBatchNo+"&fStocker="+row.fWorker+"&fPrintNum="+row.fPrintNum+"&fItemID="+row.fItemID+"&fStockID="+row.fStockID+"&fStockPlaceID="+row.fStockPlaceID);
		var URL = pathUrl("MCD?index=" + row.fItemID + "&type=99999&fEntryId=" + row.fStockID + "&fStockPlaceID=" +row.fStockPlaceID+"&fBatchNo="+row.fBatchNo);
		window.open(URL);
		/*$('#qrcode').html('');
		$("#qrcode").qrcode({
			width: 110,
			height: 110,
			correctLevel : 3,
			text: '[{"fItemID":"'+row.fItemID+'","fStockID":"'+row.fStockID+'","fBatchNo":"'+row.fBatchNo+'","fStockPlaceID":"'+row.fStockPlaceID+'"}]'
		});*/
	}
};
//点击返回
$('#back').click(function(){
	$("#useModal").modal('hide');
});
var resetColumn = [ 
	{
		field : "fName",
		align : 'left',
		valign: 'middle',
		title : '物料名称',
		edit : false,
		visible : true,
		sortable : true,
		width: '10%'
	},{
		field : "fNumber",
		align : 'left',
		valign: 'middle',
		title : '物料代码',
		edit : false,
		sortable : true,
		visible : true,
		width: '10%'
	}, {
		field : "fModel",
		align : 'left',
		valign: 'middle',
		title : '规格型号',
		edit : false,
		sortable : true,
		visible : true,
		width: '10%'
	}, {
		field : "fUnit",
		align : 'left',
		valign: 'middle',
		title : '单位',
		edit : false,
		sortable : true,
		visible : true,
		width: '10%',
		showSearch : false
	}, {
		field : "fBatchNo",
		align : 'left',
		valign: 'middle',
		title : '批次',
		sortable : true,
		edit : false,
		visible : true,
		width: '10%'
	}, {
		field : "stockName",
		align : 'left',
		valign: 'middle',
		title : '仓库名',
		sortable : true,
		edit : false,
		visible : true,
		width: '10%'
	}, {
		field : "fSPName",
		align : 'left',
		valign: 'middle',
		title : '库位',
		sortable : true,
		edit : false,
		visible : true,
		width: '10%'
	}, {
		field : "fQty",
		align : 'left',
		valign: 'middle',
		title : '数量',
		sortable : true,
		edit : false,
		visible : true,
		width: '10%'
	}, {
		field : "fSecQty",
		align : 'left',
		valign: 'middle',
		title : '辅助数量',
		sortable : true,
		edit : false,
		visible : true,
		width: '10%'
	},	{
		field : "fWorker",
		align : 'left',
		valign: 'middle',
		title : '入库人',
		edit : false,
		visible : true,
		must:true,
		sortable : true,
		width: '10%'
	},{
		field : "fOrderNo",
		align : 'left',
		valign: 'middle',
		title : '销售单号',
		edit : false,
		sortable : true,
		visible : true,
		width: '10%'
	},	{
		field : "fSupplier",
		align : 'left',
		valign: 'middle',
		title : '供应商',
		edit : false,
		visible : true,
		must:true,
		sortable : true,
		width: '10%'
	},{
		field : 'operate',
		align : 'left',
		valign: 'middle',
		title : '操作',
		formatter : isNull,
		visible : true,		
		width: '10%',
		must:true,
		formatter : function(value,row,index){
			return '<button type="button" class="btn btn-default revoke" style="font-size:12px;margin-right:5px;">打印</button>';
		},
		events : operateEvents,
		showSearch : false
}];

var colArr = [];
/*
 * @Description: 预加载 
 * @param :
 */
$(function (){
	resizeIframeHight();
//	initTable();
	initField();
	loadRecordName("EC_CX",initTable);
	$(".EC_CX",parent.document).click(function(){
		$('#inTable').bootstrapTable('refresh');
	});
});

/*
 * @Description: 初始化表
 * @param : 
 */
function initTable(){
	$("#staffTable").bootstrapTable('destroy').bootstrapTable({
		url : pathUrl("icinventory/getInvtoryLists.action"),
		height : $(window).height()*0.78,//行高
		method : "POST",
		striped : true,
		cache : false,
		editable:true,//开启编辑模式
		sidePagination : "server", // 分页方式：client客户端分页，server服务端分页（*）
		pagination : true,
		pageNumber : 1,
		pageSize : 10,
		pageList : [ 10, 30, 60, 100, 'ALL' ],
		showExport: true,
		colArr : colArr,
		exportDataType: "allServer",
		buttonsAlign:"right",  //按钮位置
		rowStyle : function(row, index) {
			var classes = [ 'success' ];
			if (index == rowIndex) {
				return {
					classes : classes[0]
				};
			}
			return {};
		},
		queryParams : function(params) {
			var data = {};
			var orderBy = params.sort + " " + params.order;      //排序列名
			if(params.sort=='fNumber'){
				orderBy = "c.fNumber"+ " " + params.order;
			}
			if(params.sort=='fBatchNo'){
				orderBy = "tem.fBatchNo"+ " " + params.order;
			}
			if(params.sort==undefined){
				orderBy = "tem.fBatchNo desc";
			}
			data.offset = params.offset +1;
			data.row = params.limit,
			data.sqlStr = sqlCombine;
			data.orderBy = orderBy;
			return data;
		},
		dataType : 'JSON',
		uniqueId : "id",
		columns : customColumn,
		onClickRow: function (row,$element) {
//			console.log(row)
			$('.success').removeClass('success');// 去除之前选中的行的，选中样式
			$($element).addClass('success');// 添加当前选中的 success样式用于区别
			index = $element.data('index');
			rowIndex = index;
			_index = index;
			page = $('.pagination .active').find("a").eq(0).text();
		},
		onLoadSuccess:function(data){
			console.log(data);
		},
		onPageChange : function(number, size) {
			if (page == number) {
				rowIndex = index;
			} else {
				$('.success').removeClass('success');
				rowIndex = "%^%%%%";
			}
		}
	});
}


/*
 * @Description: 重置按钮点击事件 
 * @param :
 */
$(".resetting").click(function(){
	$(".clean_C").val("");
	var data = dataExport;
	for(prop in data){
		if(data.hasOwnProperty(prop)){
			data[prop] = '';
		}
	}
	reset();
});



/*
 * @Description: 查询条件按回车事件
 * @param :
 */
$("#fDate,#fOperation,#fMethod,#fIP,#fLevel,#fParams,#fBillerName,#fExplanation").keypress(function(event){
	if(event.keyCode == "13"){
		initTable();
	}
});
/*
 * @Description: 空字符串格式化
 * @param :
 */
function isNull(value,row,index){
	if(value == null){
		return "";
	}else{
		return value;
	}
}